<template>
	<view class="response">
		<u-navbar
			class="navbar_top"
			back-text="取消"
			title="回答"
			:title-size="36"
			:border-bottom="false"
			:back-icon-size="0"
			back-icon-color="#000000"
			:back-text-style="{ color: '#787882', fontSize: '26rpx' }"
		>
			<view class="navbar-right u-m-r-24" slot="right" @click="doissue">
				<text
					:style="{
						color: content == '' ? '#787882' : '#FFDB28',
						fontWeight: content == '' ? 100 : 600
					}"
				>
					发布回答
				</text>
			</view>
		</u-navbar>
		<view class="problem u-line-2">{{ title }}</view>
		<view class=""><u-input v-model="content" type="textarea" placeholder="回答开门见山，能获得更多赞哦~" :clearable="false"></u-input></view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
export default {
	name: 'response',
	data() {
		return {
			title: '',
			content: '',
			problem: {}
		};
	},
	//实例创建完成后被立即调用
	created() {},
	onLoad(option) {
		this.problem = JSON.parse(decodeURIComponent(option.problem));
		console.log(this.problem);
		this.title = this.problem.q;
	},
	//挂载开始之前被调用
	beforeMount() {},
	onPullDownRefresh() {
		//监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
		console.log('refresh');
		setTimeout(function() {
			uni.stopPullDownRefresh(); //停止下拉刷新动画
		}, 1000);
	},
	//初次渲染完成
	onReady() {},
	//全局只触发一次
	onLaunch() {},
	//从后台进入前台
	onShow() {},
	//前台进入后台
	onHide() {},
	methods: {
		doissue() {
			console.log(this.content);
			if (this.content == '') {
				return;
			} else {
				this.$u.api
					.answerquestion({
						id: this.problem.id,
						content: this.content
					})
					.then(res => {
						// console.log(res);
						if (res.code == 200) {
							this.$refs.uToast.show({
								title: '提交成功!',
								type: 'success'
							});
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/knowledge/answer?problem=' + encodeURIComponent(JSON.stringify(this.problem))
								});
							}, 300);
						}
					})
					.catch(err => {
						console.log(err);
					});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.response {
	.problem {
		height: 128rpx;
		background-color: #dfdfdf;
		padding: 20rpx 24rpx;
		color: #101010;
		font-size: 32rpx;
		font-weight: 600;
	}
}
</style>
